package com.example.ljw.paperlive.ui.famliy;

import android.util.Log;

import com.example.ljw.paperlive.bean.FamliyBean;
import com.example.ljw.paperlive.config.URLConfig;
import com.example.ljw.paperlive.retrofitinterface.IRetrofitListener;
import com.example.ljw.paperlive.utils.OkHttp3Utils;

import java.io.IOException;
import java.util.Map;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * Created by LJW on 2016/11/24.
 */

public class FamliyModle implements FamliyContract.IFamliyModel {
    private Retrofit mRetrofit=null;
    @Override
    public Observable<FamliyBean> getFamliyData(Map<String, String> map) {
        //为okhttp设置拦截器
        OkHttpClient client=new OkHttpClient.Builder()
                .addNetworkInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request request = chain.request();
                        Log.i("TAG",request.url().toString());
                        return chain.proceed(request);
                    }
                })
                .build();
        mRetrofit=new Retrofit.Builder()
                .baseUrl(URLConfig.URL_BASE)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        Observable<FamliyBean> observable=mRetrofit.create(IRetrofitListener.class)
                .getFamliyData(map);
        return observable;

    }
}
